package com.qfedu.labsystem.controller;

import com.qfedu.labsystem.entity.bo.BookBO;
import com.qfedu.labsystem.entity.vo.BookVO;
import com.qfedu.labsystem.entity.vo.ResultOBJ;
import com.qfedu.labsystem.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName BookController
 * @Author ykx
 * @Date 2024/4/7 16:38
 * @Version 1.0
 */
@RestController
@RequestMapping("/adminapi/books")
public class BookController {

    @Autowired
    private BookService bookService;

    @GetMapping
    public List<BookVO> getBookList(BookBO bookBO) {
        return bookService.getBookList(bookBO);
    }

    @PostMapping
    public ResultOBJ addBookList(@RequestBody BookBO bookBO) {
        return ResultOBJ.success(bookService.addBook(bookBO));
    }

    @PostMapping("/select")
    public List<BookVO> getSelectBookList(@RequestBody BookBO bookBO) {
        return bookService.getBookList(bookBO);
    }

    @DeleteMapping("{id}")
    public ResultOBJ deleteBookList(@PathVariable Integer id) {
        return ResultOBJ.success(bookService.deleteBook(id));
    }

    @PutMapping("{id}")
    public ResultOBJ updateBookList(@PathVariable Integer id, @RequestBody BookBO bookBO) {
        bookBO.setId(id);
        return ResultOBJ.success(bookService.updateBook(bookBO));
    }

}
